import request from '../utils/request';
import {baseServerUrl} from "../utils/Constant";
import {stringify} from "qs";


export async function rolePage(params) {
  return request(baseServerUrl + `/user/sys-role/page?${stringify(params)}`,{
    method: 'GET'
  });
}

export async function roleInsert(params) {
  return request(`${baseServerUrl}/user/sys-role`, {
    method: 'POST',
    body: {
      ...params,
      method: 'post',
    }
  })
}

export async function roleDel(params) {
  return request(`${baseServerUrl}/user/sys-role`, {
    method: 'DELETE',
    body: {
      ...params,
      method: 'delete'
    }
  })
}

export async function roleEdit(params) {
  return request(`${baseServerUrl}/user/sys-role`, {
    method: 'PUT',
    body: {
      ...params,
      method: 'put'
    }
  })
}

export async function resResTree(params) {
  return request(`${baseServerUrl}/user/sys-role-resource/treeData?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function resResSave(params) {
  let body = new FormData();
  Object.keys(params).map(key => {
    body.append(key,params[key]);
  })
  return request(`${baseServerUrl}/user/sys-role-resource/save`, {
    method: 'POST',
    body: body
  })
}
